home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 3.1 KB | 162 lines | [TEXT/ttxt] |
- --<<<<
-
- in module WebImplementation
-
- class url ()
- instance variables
- scheme
- withoutScheme
- host
- user
- password
- DomainName
- port
- path
- string
- end
-
- --- Simple parser for URLS
-
- function splitstring string separator keep -> (
- local n := getOrdOne string separator
- local p1
- local p2
-
- if (n == 0) then (
- p1 := undefined
- p2 := string
- ) else (
- p1 := copyFromTo string 0 (n - 1)
- if keep then
- p2 := copyFromTo string (n - 1) (size string)
- else
- p2 := copyFromTo string n (size string)
- )
- #(p1, p2)
- )
-
- function splitstring1 string separator keep -> (
- local stuff := splitstring string separator keep
- if stuff[1] = undefined do (
- stuff := #(stuff[2], stuff[1])
- )
- stuff
- )
-
- function parseURL url -> (
- local scheme
- local host
- local stuff
- local colon := ":"[1] -- unbelievable!
- local slash := "/"[1]
- local host
- local stuff
- local withoutScheme
-
- stuff := splitstring url colon false
- scheme := stuff[1]
- withoutScheme := url := stuff[2]
-
- if ((url[1] == slash) and url[2] == slash) then (
- url := copyFromTo url 2 (size url)
- stuff := splitstring1 url slash true
- host := stuff[1]
- url := stuff[2]
- ) else (
- host := undefined
- )
-
- #(scheme, host, url, withoutScheme)
- )
-
- function parsehost host -> (
- local stuff
- local user := undefined
- local password := undefined
- local hostmachine := undefined
- local port := undefined
- local hoststuff
-
- if (host != undefined) do (
- stuff := splitstring host "@"[1] false
- hoststuff := stuff[2]
- stuff := stuff[1]
-
- if stuff != undefined do (
- stuff := splitstring1 stuff ":"[1] false
- user := stuff[1]
- password := stuff[2]
- )
-
- stuff := splitstring1 hoststuff ":"[1] false
- hostmachine := stuff[1]
- port := stuff[2]
- )
-
- #(user, password, hostmachine, port)
-
- )
-
- method init self {object url} #rest args #key string: str scheme: host: path: -> (
- apply nextMethod self args
-
- if (str = unsupplied) do (
- str := new String
- if (scheme != undefined) do str := str + scheme + ":"
- if (host != undefined) do str := str + "//" + host
- if (path != undefined) do str := str + path
- )
-
- local stuff := parseurl str
- self.scheme := stuff[1]
- self.host := stuff[2]
- self.path := stuff[3]
- self.withoutScheme := stuff[4]
-
- stuff := parseHost self.host
-
- self.user := stuff[1]
- self.password := stuff[2]
- self.domainName := stuff[3]
- self.port := stuff[4]
- self.string := str as string
-
- )
-
- method merge self {object URL} other -> (
- if (not (isaKindof other url)) do
- other := new url string: other
-
- local scheme := self.scheme
- local host := self.host
- local path := self.path
-
- if (scheme == undefined) do
- scheme := other.scheme
-
- if (host == undefined) do
- host := other.host
-
- if (path == undefined or path = "") then
- path := other.path
- else if (other.path != undefined and other.path != "") do
- path := mergePathnames other.path path
- new url scheme: scheme host: host path: path
- )
-
- function mergePathnames x y -> (
- if (y[1] == "/"[1]) do return y
- if (x[1] == "/"[1]) then (
- for i in 1 to (size x) do (
- local n := size(x) + 1 - i
- if (x[n] = "/"[1]) do (
- return (copyFromTo x 0 n) + y
- )
- )
- report 666
- ) else
- return y
- )
-
- -->>>
-